home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0098_Long filename unit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  8.1 KB  |  382 lines

  1. {
  2. I've made a Windows 95 long filename DOS unit. The file opening part is
  3. missing, maybe I will add it someday. A simple test program is after the end
  4. of part 2. }
  5.  
  6. { Long filename DOS unit, Arne de Bruijn, 19960402, Public Domain }
  7. { All functions return the errorcode, and store it in DosError in }
  8. { the Dos unit. }
  9. { The functions work only if Windows 95 is loaded! }
  10.  
  11. unit ldos;
  12. interface
  13. uses dos;
  14. type
  15.  TLSearchRec=record
  16.   Attr:longint;
  17.   CreationTime,LastAccessTime,LastModTime:comp; { See below for conversion }
  18.   HiSize,LoSize:longint;
  19.   Reserved:comp;
  20.   Name:array[0..259] of char;
  21.   ShortName:array[0..13] of char; { Only if longname exists }
  22.   Handle:word;
  23.  end;
  24.  
  25. function LFindFirst(FileSpec:pchar; Attr:word; var SRec:TLSearchRec):word;
  26. { Search for files }
  27.  
  28. function LFindNext(var SRec:TLSearchRec):word;
  29. { Find next file }
  30.  
  31. function LFindClose(var SRec:TLSearchRec):word;
  32. { Free search handle }
  33.  
  34. function LTruename(FileName:pchar; Result:pchar):word;
  35. { Return complete path, if relative uppercased longnames added, }
  36. { in buffer Result (261 bytes) }
  37.  
  38. function LGetShortName(FileName:pchar; Result:pchar):word;
  39. { Return complete short name/path for input file/path in buffer }
  40. { Result (79 bytes) }
  41.  
  42. function LGetLongName(FileName:pchar; Result:pchar):word;
  43. { Return complete long name/path for input file/path in buffer }
  44. { Result (261 bytes) }
  45.  
  46. function LFileSystemInfo(RootName:pchar; FSName:pchar; FSNameBufSize:word;
  47.  var Flags,MaxFileNameLen,MaxPathLen:word):word;
  48. { Return File System Information, for FSName 32 bytes should be sufficient }
  49. { Rootname is for example 'C:\' }
  50. { Flags: }
  51. { bit
  52. {  0   searches are case sensitive }
  53. {  1   preserves case in directory entries }
  54. {  2   uses Unicode characters in file and directory names }
  55. { 3-13 reserved (0) }
  56. { 14   supports DOS long filename functions }
  57. { 15   volume is compressed }
  58.  
  59.  
  60. function LErase(Filename:pchar):word;
  61. { Erase file }
  62.  
  63. function LMkDir(Directory:pchar):word;
  64. { Make directory }
  65.  
  66. function LRmDir(Directory:pchar):word;
  67. { Remove directory }
  68.  
  69. function LChDir(Directory:pchar):word;
  70. { Change current directory }
  71.  
  72. function LGetDir(Drive:byte; Result:pchar):word;
  73. { Get current drive and directory. Drive: 0=current, 1=A: etc. }
  74.  
  75. function LGetAttr(Filename:pchar; var Attr:word):word;
  76. { Get file attributes}
  77.  
  78. function LSetAttr(Filename:pchar; Attr:word):word;
  79. { Set file attributes }
  80.  
  81. function LRename(OldFilename,NewFilename:pchar):word;
  82. { Rename file }
  83.  
  84. function LTimeToDos(var LTime:comp):longint;
  85. { Convert 64-bit number of 100ns since 01-01-1601 UTC to local DOS format time
  86. }{ (LTime is var to avoid putting it on the stack) }
  87.  
  88. procedure UnpackLTime(var LTime:comp; var DT:DateTime);
  89. { Convert 64-bit time to date/time record }
  90. implementation
  91. function LFindFirst(FileSpec:pchar; Attr:word; var SRec:TLSearchRec):word;
  92. assembler;
  93. { Search for files }
  94. asm
  95.  push ds
  96.  lds dx,FileSpec
  97.  les di,SRec
  98.  mov cx,Attr
  99.  xor si,si
  100.  mov ax,714eh
  101.  int 21h
  102.  pop ds
  103.  sbb bx,bx
  104.  mov es:[di].TLSearchRec.Handle,ax
  105.  and ax,bx
  106.  mov [DosError],ax
  107. end;
  108.  
  109. function LFindNext(var SRec:TLSearchRec):word; assembler;
  110. { Find next file }
  111. asm
  112.  mov ax,714fh
  113.  xor si,si
  114.  les di,SRec
  115.  mov bx,es:[di].TLSearchRec.Handle
  116.  int 21h
  117.  sbb bx,bx
  118.  and ax,bx
  119.  mov [DosError],ax
  120. end;
  121.  
  122. function LFindClose(var SRec:TLSearchRec):word; assembler;
  123. { Free search handle }
  124. asm
  125.  mov ax,714fh
  126.  mov bx,es:[di].TLSearchRec.Handle
  127.  int 21h
  128.  sbb bx,bx
  129.  and ax,bx
  130.  mov [DosError],ax
  131. end;
  132.  
  133.  
  134. function LTrueName(FileName:pchar; Result:pchar):word; assembler;
  135. { Return complete path, if relative uppercased longnames added, }
  136. { in buffer Result (261 bytes) }
  137. asm
  138.  push ds
  139.  mov ax,7160h
  140.  xor cx,cx
  141.  lds si,FileName
  142.  les di,Result
  143.  int 21h
  144.  pop ds
  145.  sbb bx,bx
  146.  and ax,bx
  147.  mov [DosError],ax
  148. end;
  149.  
  150. function LGetShortName(FileName:pchar; Result:pchar):word; assembler;
  151. { Return complete short name/path for input file/path in buffer }
  152. { Result (79 bytes) }
  153. asm
  154.  push ds
  155.  lds si,FileName
  156.  les di,Result
  157.  mov ax,7160h
  158.  mov cx,1
  159.  int 21h
  160.  pop ds
  161.  sbb bx,bx
  162.  and ax,bx
  163.  mov [DosError],ax
  164. end;
  165.  
  166.  
  167. function LGetLongName(FileName:pchar; Result:pchar):word; assembler;
  168. { Return complete long name/path for input file/path in buffer }
  169. { Result (261 bytes) }
  170. asm
  171.  push ds
  172.  lds si,FileName
  173.  les di,Result
  174.  mov ax,7160h
  175.  mov cx,2
  176.  int 21h
  177.  pop ds
  178.  sbb bx,bx
  179.  and ax,bx
  180.  mov [DosError],ax
  181. end;
  182.  
  183. function LFileSystemInfo(RootName:pchar; FSName:pchar; FSNameBufSize:word;
  184.  var Flags,MaxFileNameLen,MaxPathLen:word):word; assembler;
  185. { Return File System Information, for FSName 32 bytes should be sufficient }
  186. asm
  187.  push ds
  188.  lds dx,RootName
  189.  les di,FSName
  190.  mov cx,FSNameBufSize
  191.  mov ax,71a0h
  192.  int 21h
  193.  pop ds
  194.  les di,Flags
  195.  mov es:[di],bx
  196.  les di,MaxFileNameLen
  197.  mov es:[di],cx
  198.  les di,MaxPathLen
  199.  mov es:[di],dx
  200.  sbb bx,bx
  201.  and ax,bx
  202.  mov [DosError],ax
  203. end;
  204.  
  205. function LTimeToDos(var LTime:comp):longint; assembler;
  206. { Convert 64-bit number of 100ns since 01-01-1601 UTC to local DOS format time
  207. }{ (LTime is var to avoid putting it on the stack) }
  208. asm
  209.  push ds
  210.  lds si,LTime
  211.  xor bl,bl
  212.  mov ax,71a7h
  213.  int 21h
  214.  pop ds
  215.  mov ax,cx
  216.  cmc
  217.  sbb cx,cx
  218.  and ax,cx
  219.  and dx,cx
  220. end;
  221.  
  222. procedure UnpackLTime(var LTime:comp; var DT:DateTime);
  223. { Convert 64-bit time to date/time record }
  224. begin
  225.  UnpackTime(LTimeToDos(LTime),DT);
  226. end;
  227.  
  228. function LMkDir(Directory:pchar):word; assembler;
  229. asm
  230.  push ds
  231.  lds dx,Directory
  232.  mov ax,7139h
  233.  int 21h
  234.  pop ds
  235.  sbb bx,bx
  236.  and ax,bx
  237.  mov [DosError],ax
  238. end;
  239.  
  240. function LRmDir(Directory:pchar):word; assembler;
  241. asm
  242.  push ds
  243.  lds dx,Directory
  244.  mov ax,713ah
  245.  int 21h
  246.  pop ds
  247.  sbb bx,bx
  248.  and ax,bx
  249.  mov [DosError],ax
  250. end;
  251.  
  252. function LChDir(Directory:pchar):word; assembler;
  253. asm
  254.  push ds
  255.  lds dx,Directory
  256.  mov ax,713bh
  257.  int 21h
  258.  pop ds
  259.  sbb bx,bx
  260.  and ax,bx
  261.  mov [DosError],ax
  262. end;
  263.  
  264. function LErase(Filename:pchar):word; assembler;
  265. asm
  266.  push ds
  267.  lds dx,Filename
  268.  mov ax,7141h
  269.  int 21h
  270.  pop ds
  271.  sbb bx,bx
  272.  and ax,bx
  273.  mov [DosError],ax
  274. end;
  275.  
  276. function LGetAttr(Filename:pchar; var Attr:word):word; assembler;
  277. asm
  278.  push ds
  279.  lds dx,Filename
  280.  mov ax,7143h
  281.  xor bl,bl
  282.  int 21h
  283.  pop ds
  284.  les di,Attr
  285.  mov es:[di],cx
  286.  sbb bx,bx
  287.  and ax,bx
  288.  mov [DosError],ax
  289. end;
  290.  
  291. function LSetAttr(Filename:pchar; Attr:word):word; assembler;
  292. asm
  293.  push ds
  294.  lds dx,Filename
  295.  mov ax,7143h
  296.  mov bl,1
  297.  mov cx,Attr
  298.  int 21h
  299.  pop ds
  300.  sbb bx,bx
  301.  and ax,bx
  302.  mov [DosError],ax
  303. end;
  304.  
  305. function LGetDir(Drive:byte; Result:pchar):word; assembler;
  306. asm
  307.  cld
  308.  les di,Result
  309.  mov al,Drive
  310.  mov dl,al
  311.  dec al
  312.  jns @GotDrive
  313.  mov ah,19h
  314.  int 21h
  315. @GotDrive:
  316.  add al,41h
  317.  mov ah,':'
  318.  stosw
  319.  mov ax,'\'
  320.  stosw
  321.  push ds
  322.  push es
  323.  pop ds
  324.  mov si,di
  325.  dec si
  326.  mov ax,7147h
  327.  int 21h
  328.  pop ds
  329.  sbb bx,bx
  330.  and ax,bx
  331.  mov [DosError],ax
  332. end;
  333.  
  334. function LRename(OldFilename,NewFilename:pchar):word; assembler;
  335. asm
  336.  push ds
  337.  lds dx,OldFilename
  338.  les di,NewFilename
  339.  mov ax,7156h
  340.  int 21h
  341.  pop ds
  342.  sbb bx,bx
  343.  and ax,bx
  344.  mov [DosError],ax
  345. end;
  346.  
  347. end.
  348.  
  349.  
  350. === LDOSTEST.PAS
  351. { Simple sample for LDOS unit, Arne de Bruijn, 19960402, Public Domain }
  352. uses ldos,strings,dos;
  353. type string2=string[2];
  354. function Str0(B:byte):string2;
  355. begin Str0[0]:=#2; Str0[1]:=char(B div 10+48); Str0[2]:=char(B mod 10+48);
  356. end;
  357. var
  358.  Buf,BufO:array[0..261] of char;
  359.  SRec:TLSearchRec;
  360.  DT:DateTime;
  361.  LN,SN:pchar;
  362.  W1,W2,W3:word;
  363. begin
  364.  Write('Enter path:'); ReadLn(Buf);
  365.  WriteLn('LFileSystemInfo:',LFileSystemInfo(Buf,BufO,32,W1,W2,W3),
  366.   ' = ',BufO,',',W1,',',W2,',',W3);
  367.  WriteLn('LTruename:',LTrueName(Buf,BufO),' = ',BufO);
  368.  WriteLn('LGetShortName:',LGetShortName(Buf,BufO),' = ',BufO);
  369.  WriteLn('LGetLongName:',LGetLongName(Buf,BufO),' = ',BufO);
  370.  LFindFirst(Buf,16,SRec);
  371.  while DosError=0 do begin
  372.    UnpackLTime(SRec.lastmodtime,DT);
  373.    if SRec.ShortName[0]=#0 then
  374.     begin SN:=@SRec.name; ln:=nil; end
  375.    else
  376.     begin SN:=@SRec.shortname; ln:=@SRec.name; end;
  377.    with DT do WriteLn(SN,'':13-StrLen(SN),SRec.LoSize:9,
  378.      ' ',Day:3,'-',Str0(Month),'-',Year,' ',Hour:2,':',Str0(Min),' ',LN);
  379.    LFindNext(SRec); end;
  380.  LFindClose(SRec);
  381. end.
  382.